package scripts
{
	import dataObjects.Invite;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import mx.containers.Box;
	import spark.components.Button;
	import mx.controls.ProgressBar;
	import mx.core.Application;
	import mx.core.FlexGlobals;
	import mx.managers.PopUpManager;	
	
	public class Mask extends Box
	{
		private static var _mask:Mask;
		private var invite:Invite;
		
		private var _message:String;
		
		public function Mask(inv:Invite)
		{
			super();
			this.invite = inv;
			this.horizontalCenter=true;
		}
		
		public static function show(message:String, parent:Sprite=null, inv:Invite=null):Mask{
			
			_mask = new Mask(inv);			
			_mask._message = message;
			PopUpManager.addPopUp(_mask, parent||Sprite(Application.application), true);
			PopUpManager.centerPopUp(_mask);
			
			return _mask;	
		}
		
		public static function close():void {
			PopUpManager.removePopUp(_mask);
		}
		
		public function cancelClickHandler(event:MouseEvent):void
		{	
			Collectomania(FlexGlobals.topLevelApplication).uiController.cancelGameInvite(invite.askingUsername, invite.receivingUsername, invite.giveCard.instanceID, invite.wantCard.instanceID, invite.type);
			return;
		} 
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			var pb:ProgressBar = new ProgressBar();
			pb.label = _message||"Please wait...";
			pb.indeterminate = true;
			pb.labelPlacement= 'center';
			pb.setStyle('barColor', uint(0xAEAEAE));
			pb.height = 26;
			
			var cancelButton:Button = new Button();
			cancelButton.label = "Cancel";
			cancelButton.height=30;
			cancelButton.width=60;	
			
			addChild(pb);				
			addChild(cancelButton);
			cancelButton.addEventListener(MouseEvent.CLICK,this.cancelClickHandler);
		}
		
		
		
		
	}
}